package com.ruoyi.chy.service.impl;

import java.util.List;

import com.ruoyi.chy.mapper.OrdersMapper;
import com.ruoyi.chy.mapper.ServiceDetailsMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.ruoyi.chy.mapper.OrderDetailsMapper;
import com.ruoyi.chy.domain.OrderDetails;
import com.ruoyi.chy.service.IOrderDetailsService;

/**
 * 订单详细Service业务层处理
 * 
 * @author liuweichao
 * @date 2025-05-30
 */
@Service
public class OrderDetailsServiceImpl implements IOrderDetailsService 
{
    @Autowired
    private OrderDetailsMapper orderDetailsMapper;

    @Autowired
    private OrdersMapper ordersMapper;

    @Autowired
    private ServiceDetailsMapper serviceDetailsMapper;

    /**
     * 查询订单详细
     * 
     * @param id 订单详细主键
     * @return 订单详细
     */
    @Override
    public OrderDetails selectOrderDetailsById(Integer id)
    {
        return orderDetailsMapper.selectOrderDetailsById(id);
    }

    /**
     * 查询订单详细列表
     * 
     * @param orderDetails 订单详细
     * @return 订单详细
     */
    @Override
    public List<OrderDetails> selectOrderDetailsList(OrderDetails orderDetails)
    {
        return orderDetailsMapper.selectOrderDetailsList(orderDetails);
    }

    /**
     * 新增订单详细
     * 
     * @param orderDetails 订单详细
     * @return 结果
     */
    @Override
    public int insertOrderDetails(OrderDetails orderDetails)
    {
        return orderDetailsMapper.insertOrderDetails(orderDetails);
    }

    /**
     * 修改订单详细
     * 
     * @param orderDetails 订单详细
     * @return 结果
     */
    @Override
    public int updateOrderDetails(OrderDetails orderDetails)
    {
        return orderDetailsMapper.updateOrderDetails(orderDetails);
    }

    /**
     * 批量删除订单详细
     * 
     * @param ids 需要删除的订单详细主键
     * @return 结果
     */
    @Override
    public int deleteOrderDetailsByIds(Integer[] ids)
    {
        return orderDetailsMapper.deleteOrderDetailsByIds(ids);
    }

    /**
     * 删除订单详细信息
     * 
     * @param id 订单详细主键
     * @return 结果
     */
    @Override
    public int deleteOrderDetailsById(Integer id)
    {
        return orderDetailsMapper.deleteOrderDetailsById(id);
    }
//    一对一，通过查询订单编号orderId查询订单详细信息
    @Override
    public List<OrderDetails> selectOrderDetailsByOrderId(Integer orderId) {
        List<OrderDetails> list = orderDetailsMapper.selectOrderDetailsByOrderId(orderId);
        for (OrderDetails orderDetails : list) {
            // 根据订单编号查询订单信息
            orderDetails.setOrders(ordersMapper.selectOrdersById(orderDetails.getOrderId()));
            orderDetails.setServiceDetails(serviceDetailsMapper.selectServiceDetailsById(orderDetails.getServiceId()));
        }
        return list;
    }
//    一对一，通过查询服务编号serviceId查询订单详细信息
    @Override
    public List<OrderDetails> selectOrderDetailsByServiceId(Integer serviceId) {
        List<OrderDetails> list = orderDetailsMapper.selectOrderDetailsByServiceId(serviceId);
        return list;
    }


}
